﻿using System;
using System.Drawing;
using System.Windows.Forms;

namespace IchiaTester
{
    public partial class LoadingForm : Form
    {
        public LoadingForm()
        {
            InitializeComponent();

            this.lbAppName.Text = SystemSetting.SOFTWARE_NAME;
            this.lbAppVer.Text = SystemSetting.SOFTWARE_VERSION;
            this.lbReleaseDate.Text = SystemSetting.RELEASE_DATE;
        }

        public void AppendText(string message, bool isError)
        {
            rtLoadingMsg.SelectionStart = rtLoadingMsg.TextLength;
            rtLoadingMsg.SelectionLength = 0;

            rtLoadingMsg.SelectionColor = isError ? Color.Red : Color.Black;
            rtLoadingMsg.AppendText(message + "\n");
            rtLoadingMsg.SelectionColor = rtLoadingMsg.ForeColor;
        }

        public void AppendMessage(string message)
        {
            if (rtLoadingMsg.InvokeRequired)
            {
                rtLoadingMsg.Invoke(new Action<string>(AppendMessage), message);
            }
            else
            {
                rtLoadingMsg.AppendText(message + Environment.NewLine);
            }
        }

        public void AppendMessage(string message, bool isError = false)
        {
            if (rtLoadingMsg.InvokeRequired)
            {
                rtLoadingMsg.Invoke(new Action<string, bool>(AppendMessage), message, isError);
            }
            else
            {
                rtLoadingMsg.SelectionStart = rtLoadingMsg.TextLength;
                rtLoadingMsg.SelectionLength = 0;

                rtLoadingMsg.SelectionColor = isError ? Color.Red : Color.Black;
                rtLoadingMsg.AppendText(message + Environment.NewLine);
                rtLoadingMsg.SelectionColor = rtLoadingMsg.ForeColor;
            }
        }
    }
}